
from Base import *
from Header import *

class CErrorElement(CInfoElement):
    _gName = "Error Element"
    _gNameErrOct = "Error Octet"

    _gInfoLength = 1 #error element length is 1 byte(not include element header)
    _gErrDescDict = {0:"",
                     1:"Service currentely not available",
                     3:"Unknown version",
                     4:"Unknown message type",
                     5:"Unknown data in message",
                     10:"No access: service not configured",
                     12:"No access: other reasons",
                     13:"Invalid session ID",
                     14:"Parameters error in OTA configuration message",
                     16:"Descriptor in Provision message does not match the data in DCM",
                     19:"General non-specific error",
                     23:"VIN does not matched",
                     25:"Provision request not processed",
                     27:"Invalid DCM service activation"}

    def __init__(self, name=_gName):
        super(CErrorElement, self).__init__(name)
        self._errOct = 0
        self._hlColor = 'Error'

    def InitSubItem(self):
        name = self._gNameHeader
        item = CEleHeader(name, recommendedLen = self._gInfoLength)
        self._subList[name] = item
        self._nameList.append(name)

        self.CreateSubItem(self._gNameErrOct)


    def ParseElement(self, dataStr):
        self._errOct = dataStr.GetByte()
        item = self._subList[self._gNameErrOct]
        item._rawStr = DATA_FORMAT.format(self._errOct)

        if self._errOct in self._gErrDescDict:
            item._infoStr = self._gErrDescDict[self._errOct]
        else:
            item._errStr = "Invalid Error Octet"
